package main

import (
	_ "github.com/go-sql-driver/mysql"
	"html/template"
	"im/ctrl"
	"log"
	"net/http"
)

func RegisterView()  {
	tmpl,err:=template.ParseGlob("view/**/*")
	if err!=nil {
		log.Fatalln(err.Error())
	}
	for _,v:=range tmpl.Templates(){
		tplName:=v.Name()
		http.HandleFunc(tplName, func(writer http.ResponseWriter, request *http.Request) {
			tmpl.ExecuteTemplate(writer,tplName,nil)
		})
	}
}
func main(){
	//注冊页面
	http.HandleFunc("/user/login", ctrl.UserLogin )
	http.HandleFunc("/user/register", ctrl.UserRegister )
	//指定提供目录文件
	http.Handle("/asset/",http.FileServer(http.Dir(".")))
	RegisterView()
	http.ListenAndServe(":8080",nil)
}
